/******************************** ************************ *********************************/
/********************************      网络请求工具类      *********************************/
/******************************** ************************ *********************************/

import React, {Component} from 'react';

/*
* 网络请求相关
* */
class Api extends Component {
    static stringIp = "http://116.62.173.197:8881";

    static orderCourse = this.stringIp + "/sumSchool/order/orderCourse";

    static bodyParas = {
        token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdW5TY2hvb2xfaXNzIjoiU2VydmljZSIsIm9wZW5pZCI6InRlc3QxMjMiLCJvcGVuaWRNZDUiOiJjYzAzZTc0N2E2YWZiYmNiZjhiZTc2NjhhY2ZlYmVlNSIsInN1blNjaG9vbF91c2VySWQiOiI1NyIsImV4cCI6MTg2ODI0MDcyMSwiaWF0IjoxNTUyODgwNzIxLCJzdW5TY2hvb2xfYXVkIjoiQVBQIn0.Gka1XMVLDyuIVVjwyeQgB_aMr4eAW3jN-5Ku1vMCp00',
        page: '1',
        pageSize: '2'
    };

    static getOrderCourse(method, bodyParas) {
        return new Promise((resolve, reject) => {
            fetch(this.orderCourse, {
                method: method,
                headers: {'Content-Type': 'application/json'},
                body: JSON.stringify(bodyParas)
            })
                .then((response) => response.json())
                .then((responseData) => {
                    resolve(JSON.stringify(responseData));
                    reject('错误');
                })
                .catch((error) => {
                    reject('' + error);
                })
                .done();
        });
    }

    static getData(url, method, bodyParas) {
        return new Promise((resolve, reject) => {
            fetch(url)
                .then((response) => response.json())
                .then((responseData) => {
                    resolve(JSON.stringify(responseData));
                    reject('错误');
                })
                .catch((error) => {
                    reject('' + error);
                })
                .done();
        });
    }
}

export default Api;